#include "main/utils.h"
using namespace std;

vector<int> countBits_solution1(const int &n) {
  vector<int> ret;
  for (int i = 0; i <= n; ++i) {
    int cur_bits = 0;
    int cur_num = i;
    while (cur_num) {
      ++cur_bits;
      cur_num = cur_num & (cur_num - 1);
    }
    ret.push_back(cur_bits);
  }
  return ret;
}

vector<int> countBits_solution2(const int &n) {
  vector<int> ret(1, 0);
  for (int i = 1; i <= n; ++i) {
    auto tmp = ret[i & (i - 1)] + 1;
    ret.push_back(tmp);
  }
  return ret;
}

vector<int> countBits_solution3(const int &n) {
  vector<int> ret = {0, 1};
  for (int i = 2; i <= n; ++i) {
    int tmp = (i & 1) ? ret[i >> 1] + 1 : ret[i >> 1];
    ret.push_back(tmp);
  }
  return ret;
}

int main() {
  int n = 4;
  vector<int> ret = countBits_solution1(n);
  printVec("countBits solution1", ret);

  ret = countBits_solution2(n);
  printVec("countBits solution2", ret);

  ret = countBits_solution3(n);
  printVec("countBits solution3", ret);

  return 0;
}
